import { defineStore } from 'pinia'
import axios from 'axios'


interface movieItemType{
    albumId:number,
    albumName:string
}

type movieListType = movieItemType[]

interface movieStateType{
    movieList:movieListType;
    isMovie:boolean;
}

const useMoviestate = defineStore('movie',{
    state:()=>{
        return{
            movieList:[],
            isMovie:true
        }
    },
    // actions中的方法是可以异步修改数据的
    actions:{
        async getMovieList(){
            const result = await axios.get(`https://pcw-api.iqiyi.com/search/recommend/list?channel_id=1&data_type=1&mode=11&page_id=2&ret_num=48&session=b9fd987164f6aa47fad266f57dffaa6a`);
            this.movieList = result.data.data.list.map((item:any)=>{
                return { albumId:item.albumId,albumName:item.albumName }
            })

        }
    }
})

export default useMoviestate